package org.ants.basecomponent.action.demo;

import java.util.List;

import net.sf.json.JSONObject;

import org.ants.basecomponent.action.base.BaseAction;
import org.ants.basecomponent.config.Globals;
import org.ants.basecomponent.pojo.pagination.PageRequest;
import org.ants.basecomponent.pojo.pagination.PageResponse;
import org.ants.basecomponent.util.JSONUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tinygroup.vfs.FileObject;


@Controller
@RequestMapping("/uidemo")
public class DemoAction extends BaseAction{
    @RequestMapping(value = "/{id}/manage")
    public String execute(@PathVariable("id")String id,Model model) {
        model.addAttribute("id",id);
        return Globals.getDefaultViewsPath()+"/page/uidemo/demo/menu";
    }
    
    @RequestMapping(value = "/btTable")
    public String btTable(Model model) {
        return Globals.getDefaultViewsPath()+"/page/uidemo/table/btTable";
    }
    
    @RequestMapping(value = "/reportIndex")
    public String reportIndex(Model model) {
        return Globals.getDefaultViewsPath()+"/page/report/btTable";
    }
    
    @RequestMapping(value = "/reportEdit")
    public String reportEdit(Model model) {
        return Globals.getDefaultViewsPath()+"/page/report/reportEdit";
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "/bt_table_data")
    @ResponseBody
    public PageResponse ztreeData(PageRequest pageRequest,Model model) {
    	FileObject fileObject = this.getFileObject("bt_table_data.json");
    	JSONObject jsonobj = JSONUtils.getJsonByFileObject(fileObject.getInputStream());
    	PageResponse pageResponse = 
    			new PageResponse(pageRequest.getPageNo(), pageRequest.getPageSize());
    	pageResponse.setRows((List)jsonobj.get("rows"));
        return pageResponse;
    }
}
